package com.xiaojianone.order;

import com.alibaba.cloud.nacos.NacosConfigManager;
import com.alibaba.nacos.api.config.ConfigService;
import com.alibaba.nacos.api.config.listener.Listener;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean;

import java.util.concurrent.Executor;
import java.util.concurrent.Executors;

/**
 * ClassName  OrderMainApplication
 * Author  XiaojianOne
 * Date  2025/3/10 8:27
 * Version  8.0
 */

@EnableFeignClients
@EnableDiscoveryClient
@SpringBootApplication
public class OrderMainApplication {
    public static void main(String[] args) {

        SpringApplication.run(OrderMainApplication.class,args);
    }


    @Bean
    public ApplicationRunner applicationRunner(NacosConfigManager nacosConfigManager){

        return (ApplicationArguments args) ->{
            ConfigService configService = nacosConfigManager.getConfigService();
            configService.addListener("service-order.properties", "DEFAULT_GROUP",
                    new Listener() {
                        @Override
                        public Executor getExecutor() {
                            return Executors.newFixedThreadPool(4);
                        }

                        @Override
                        public void receiveConfigInfo(String s) {
                            System.out.println("接收到配置信息："+s);
                            System.out.println("邮箱通知");
                        }
                    });

            System.out.println("=========启动成功=========");
        };
    }
}
